package cn.hnwlgc.service.impl;

import cn.hnwlgc.mapper.UserMapper;
import cn.hnwlgc.pojo.User;
import cn.hnwlgc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper UserMapper;

    @Override
    public User getById(Integer id) {
        return UserMapper.getById(id);
    }

    @Override
    public User login(User user) {
        return UserMapper.getByUsernameAndPassword(user);
    }

    @Override
    public void add(User user) {
        if (user.getImage() == null || user.getImage().isEmpty()) {
            user.setImage("/image/default.jpg");
        }
        UserMapper.add(user);
    }

    @Override
    public void update(User user) {
        UserMapper.update(user);
    }
}
